/*
 * WIN32 Events for POSIX
 * Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
 * Copyright (C) 2011 - 2019 by NeoSmart Technologies
 * This code is released under the terms of the MIT License
 */

// 移植了Windows下的等待单个和多个事件的方法。
// 文件来源于github,原命名空间是neosmart。
// 为方便使用在这里改为qcutil
#pragma once

#ifndef WAIT_TIMEOUT
#include <errno.h>
#define WAIT_TIMEOUT ETIMEDOUT
#define WAIT_OBJECT_0 (0)
#endif

#include <stdint.h>

namespace qcutil {
    // Type declarations
    struct neosmart_event_t_;
    typedef neosmart_event_t_ *neosmart_event_t;

    // Constant declarations
    const uint64_t WAIT_INFINITE = ~((uint64_t)0);

    // Function declarations
    neosmart_event_t CreateEvent(bool manualReset = false, bool initialState = false);
    int DestroyEvent(neosmart_event_t event);
    int WaitForEvent(neosmart_event_t event, uint64_t milliseconds = WAIT_INFINITE);
    int SetEvent(neosmart_event_t event);
    int ResetEvent(neosmart_event_t event);
    int WaitForMultipleEvents(neosmart_event_t *events, int count, bool waitAll,
                              uint64_t milliseconds);
    int WaitForMultipleEvents(neosmart_event_t *events, int count, bool waitAll,
                              uint64_t milliseconds, int &index);
    int PulseEvent(neosmart_event_t event);
} // namespace neosmart
